#ifndef SNESCONTROLLER_H
#define SNESCONTROLLER_H

/*******************************************************************
  THIS SOURCE IS BASED ON SNES4ALL CHUS'S WORK
  SEE http://chui.dcemu.co.uk/snes4all.html
*******************************************************************/

#include <QWidget>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <signal.h>
#include <QApplication>


#include "snes9x.h"
#include "memmap.h"
#include "debug.h"
#include "ppu.h"
#include "snapshot.h"
#include "gfx.h"
#include "display.h"
#include "apu.h"
#include "port.h"


#define bzero(A,B) memset(A,0,B)

#ifdef __SYMBIAN32__
#define DATA_PREFIX ".\\data\\"
//#define AUTOLOAD "e:\\data\\demo.smc"
#else
#define DATA_PREFIX "data/"
//#define AUTOLOAD "vSun\SMRPG_US.smc"
#endif

extern int QTsnes4all_frameskip;
extern int QTsnes4all_sound_enable;
extern int QTsnes4all_transparency;
extern int QTsnes4all_throttle;
extern char QTsnes4all_image_file[];
extern int QTsnes4all_emulating;
extern unsigned QTsnes4all_timeslice;
extern int QTsnes4all_sound_throttle;

extern unsigned QTsnes4all_max_vcounter;
extern long QTsnes4all_vcounter[];

extern unsigned QTsnes4all_apu_hmax;

#ifdef NORES256
#define QTSNES4ALL_SCREEN_WIDTH 320
#define QTSNES4ALL_SCREEN_HEIGHT 240
#define QTSNES4ALL_SCREEN_PAD (QTSNES4ALL_SCREEN_WIDTH - 256)/2
#else
#define QTSNES4ALL_SCREEN_WIDTH 256
#define QTSNES4ALL_SCREEN_HEIGHT 240
#define QTSNES4ALL_SCREEN_PAD (QTSNES4ALL_SCREEN_WIDTH - 256)/2
#endif
#define QTSNES4ALL_SCREEN_WIDTH_BUFFER 512
#define QTSNES4ALL_SCREEN_HEIGHT_BUFFER 478
#define QTSNES4ALL_SCREEN_DEPTH_BYTES 2
#define QTSNES4ALL_SCREEN_PITCH (QTSNES4ALL_SCREEN_WIDTH_BUFFER * QTSNES4ALL_SCREEN_DEPTH_BYTES)
#define QTSNES4ALL_SCREEN_PITCH_LO (QTSNES4ALL_SCREEN_WIDTH * QTSNES4ALL_SCREEN_DEPTH_BYTES)
#define QTSNES4ALL_SCREEN_PITCH2 (QTSNES4ALL_SCREEN_PITCH >> 1)

#ifdef NORES256
#define getY(Y) (QTSNES4ALL_SCREEN_WIDTH * QTSNES4ALL_SCREEN_DEPTH_BYTES * (Y) )
#define getY2(Y) (((QTSNES4ALL_SCREEN_WIDTH * QTSNES4ALL_SCREEN_DEPTH_BYTES)>>1) * (Y) )
#else
#define getY(Y) ( (Y) << 9 )
#define getY2(Y) ( (Y) << 8 )
#endif

#define QTSNES4ALL_SCREEN_DEPTH QImage::Format_RGB555

#define COUNT(a) (sizeof(a) / sizeof(a[0]))

extern quint32 cl, cs;
extern int MouseXpos, MouseYpos, MouseLbutton, MouseRbutton, SuperscopeTurbo, SuperscopeCursor;
extern quint32 MouseButton;
extern int snes4all_hires;

#ifndef _ZAURUS
int S9xMinCommandLineArgs ();

void S9xGraphicsMode ();

void S9xTextMode ();
#endif


void S9xInitDisplay (int /*argc*/, char ** /*argv*/);

void S9xDeinitDisplay ();

void S9xSetPalette ();

void SavePalette ();
void S9xSetTitle (const char *  title);

#ifndef _ZAURUS
const char *S9xSelectFilename (const char *def, const char *dir1,
                const char *ext1, const char *title);

void S9xParseDisplayArg (char **argv, int &ind, int);

void S9xExtraUsage ();

bool8 S9xReadMousePosition (int  which1 , int &x , int &y ,
                uint32 &buttons );
bool8 S9xReadSuperScopePosition (int &x , int &y ,
                 uint32 &buttons );
#endif

void S9xMessage (int /* type */, int /* number */, const char *message);


bool JustifierOffscreen();
void JustifierButtons(uint32& justifiers);

const char *S9xGetFilenameInc (const char *e);
const char *S9xGetSnapshotDirectory ();
START_EXTERN_C
char* osd_GetPackDir();
END_EXTERN_C

#endif // SNESCONTROLLER_H
